﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using Axis.Dao.Product;
using Axis.BusinessObject.Axis.BusinessObject;
using Axis.BusinessObject.Product;
namespace Sotipha.Web.Views.Home
{
    public class CFeatureProctuct : CPage
    {
        public string GetProductType(string ProductType, int GroupID, string TypeName)
        {
            StringBuilder Result = new StringBuilder();
            CProductDao coreProduct = new CProductDao();
            string inputValue = string.Format("<InputValue  Context=\"FrontEnd\" ProductTypeID=\"{0}\"/>", ProductType);
            IList<CProductGroup> list = coreProduct.GetProductGroup(inputValue);
            string Language = Session["lang"].ToString();
            if (list != null)
                if (list.Count > 0 && GroupID == -1)
                    GroupID = list[0].ID;
            foreach (var Item in list)
            {
                string Active = "";
                if (Item.ID == GroupID) Active = "class=\"active\" id=\"GroupActive\"";
                Result.AppendFormat("<li><a href=\"../{2}/Default.aspx?GroupID={3}\" {0}>{1}</a></li>", Active, Language == "vi" ? Item.Name_VN : Item.Name_EN, TypeName, Item.ID);

            }
            return Result.ToString();
        }

        public string GetProductArrival(string ProductType, int GroupID, string TypeName)
        {
            StringBuilder Result = new StringBuilder();
            CProductDao coreProduct = new CProductDao();
            string inputValue = string.Format("<InputValue  Context=\"ProductArrival\" ProductTypeID=\"{0}\" GroupID=\"{1}\"/>", ProductType, GroupID);
            IList<CProduct> list = coreProduct.GetProductByCondition(inputValue);
            string Language = Session["lang"].ToString();
            if (list == null)
                return "";
            foreach (var Item in list)
            {
                string Link = BuildLink(Item);
                Result.AppendFormat("<li><a href=\"{1}\"> <img src=\"{0}\"></a><div class=\"tt\"><a href=\"{1}\">{2}</a></div></li>", Item.Thumbnail, Link, Language == "vi" ? Item.Name_VN : Item.Name_EN);
            }
            return Result.ToString();
        }

        public string GetProductFeature(string ProductType, string TypeName)
        {
            StringBuilder Result = new StringBuilder();
            CProductDao coreProduct = new CProductDao();
            string inputValue = string.Format("<InputValue  Context=\"ProductFeature\" ProductTypeID=\"{0}\" />", ProductType);
            IList<CProduct> list = coreProduct.GetProductByCondition(inputValue);
            string Language = Session["lang"].ToString();
            if (list == null)
                return "";

            string Pattern = "<div class=\"ca-item ca-item-{0}\" style=\"position: absolute; left: {5}px;\">" +
                        "<div class=\"ca-item-main\">" +
                            "<div class=\"image\">" +
                                "<a href=\"../{1}/ProductDetail.aspx?ID={2}\">" +
                                    "<img src=\"{3}\" style=\"width:100px; height:100px\"></a>" +
                            "</div>" +
                            "<div class=\"tt\">" +
                                "<a href=\"{6}\">{4}</a></div>" +
                        "</div>" +
                    "</div>";
            int i = 0;
            foreach (var Item in list)
            {
                string Link = BuildLink(Item);
                Result.AppendFormat(Pattern, i + 1, TypeName, Item.ID, Item.Thumbnail, Language == "vi" ? Item.Name_VN : Item.Name_EN, 198 * i, Link);
                i++;
            }
            return Result.ToString();
        }
        public string GetProductBestSeller(string ProductType, string TypeName)
        {
            ProductType = "-1";
            StringBuilder Result = new StringBuilder();
            CProductDao coreProduct = new CProductDao();
            string inputValue = string.Format("<InputValue  Context=\"ProductFeature\" ProductTypeID=\"{0}\" />", ProductType);
            IList<CProduct> list = coreProduct.GetProductByCondition(inputValue);
            string Language = Session["lang"].ToString();
            if (list == null)
                return "";

            string Pattern = "<div class=\"ca-item ca-item-{0}\" style=\"position: absolute; left: {5}px;\">" +
                        "<div class=\"ca-item-main\">" +
                            "<div class=\"image\">" +
                                "<a href=\"../{1}/ProductDetail.aspx?ID={2}\">" +
                                    "<img src=\"{3}\"></a>" +
                            "</div>" +
                            "<div class=\"tt\">" +
                                "<a href=\"{6}\">{4}</a></div>" +
                        "</div>" +
                    "</div>";
            int i = 0;
            foreach (var Item in list)
            {
                string Link = BuildLink(Item);
                Result.AppendFormat(Pattern, i + 1, TypeName, Item.ID, Item.Thumbnail, Language == "vi" ? Item.Name_VN : Item.Name_EN, 198 * i, Link);
                i++;
            }
            return Result.ToString();
        }

        public string GetGroupBestSeller(string ProductType, string TypeName)
        {          
            StringBuilder Result = new StringBuilder();
            CProductDao coreProduct = new CProductDao();
            string inputValue = string.Format("<InputValue  Context=\"GroupBestSeller\" ProductTypeID=\"{0}\" />", ProductType);
            IList<CProduct> list = coreProduct.GetProductByCondition(inputValue);
            string Language = Session["lang"].ToString();
            if (list == null)
                return "";

            string Pattern = "<div class=\"ca-item ca-item-{0}\" style=\"position: absolute; left: {5}px;\">" +
                        "<div class=\"ca-item-main\">" +
                            "<div class=\"image\">" +
                                "<a href=\"../{1}/ProductDetail.aspx?ID={2}\">" +
                                    "<img src=\"{3}\" style=\"width:100px; height:100px\"></a>" +
                            "</div>" +
                            "<div class=\"tt\">" +
                                "<a href=\"{6}\">{4}</a></div>" +
                        "</div>" +
                    "</div>";
            int i = 0;
            foreach (var Item in list)
            {
                string Link = BuildLink(Item);
                Result.AppendFormat(Pattern, i + 1, TypeName, Item.ID, Item.Thumbnail, Language == "vi" ? Item.Name_VN : Item.Name_EN, 198 * i, Link);
                i++;
            }
            return Result.ToString();
        }
        public string BuildLink(CProduct Item)
        {
            string Result = "";
            switch (Item.ProductTypeID)
            {
                case 1:
                    Result = "../Towntalk/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 2:
                    Result = "../Lacquerware/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 3:
                    Result = "../Gifts/ProductDetail.aspx?ID=" + Item.ID;
                    break;
                case 4:
                    Result = "../Sale/ProductDetail.aspx?ID=" + Item.ID;
                    break;
            }
            return Result;
        }

    }
}